package com.kuang.controller;

import com.kuang.pojo.AstControllerPoweron;
import com.kuang.pojo.AstControllerRegister;
import com.kuang.service.asset.AstControllerPoweronService;
import com.kuang.service.asset.AstControllerRegisterService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;
@Controller
@RequestMapping("/asset/")
public class AstControllerRegisterController {

    @Resource
    AstControllerRegisterService astControllerRegisterService;

    /**
     * 设备注册 全部数据
     * @param model
     * @return
     */
    @RequestMapping("getAstControllerRegisters")
    public String getAstControllerRegisters(Model model){
        List<AstControllerRegister> astControllerRegisters = astControllerRegisterService.selectAll();
        model.addAttribute("datas",astControllerRegisters);
        model.addAttribute("device_code","");
        model.addAttribute("ver","");
        return "mqtt/ast_controller_register_list";
    }

    /**
     * 设备注册 全部数据 通过条件
     * @param model
     * @return
     */
    @PostMapping("getAstControllerRegistersByExample")
    public String getAstControllerRegistersByExample(AstControllerRegister astControllerRegister,Model model){
        List<AstControllerRegister> astControllerRegisters = astControllerRegisterService.selectAllByExample(astControllerRegister);
        model.addAttribute("datas",astControllerRegisters);
        model.addAttribute("device_code",astControllerRegister.getDevice_code());
        model.addAttribute("ver",astControllerRegister.getVer());
        return "mqtt/ast_controller_register_list";
    }

    /**
     * 获取设备信息通过id
     * @param model
     * @return
     */
    @RequestMapping("getAstControllerRegisterById/{id}")
    public String getAstControllerRegisterById(@PathVariable("id") String id, Model model){
        AstControllerRegister astControllerRegister = new AstControllerRegister();
        astControllerRegister.setAst_controller_register_id(id);
        List<AstControllerRegister> astControllerRegisters = astControllerRegisterService.selectAllByExample(astControllerRegister);
        model.addAttribute("data",astControllerRegisters.get(0));
        return "mqtt/ast_controller_register_from";
    }

}
